package com.thunder.component;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import com.thunder.utils.Constant;
import com.thunder.utils.GameUtil;

public class EnemyFly {
	private final BufferedImage image;
	
	private final int y;
	private int x;
	private int time;
	private final int AppearTime;
	
	public EnemyFly(int x1) {
		x = x1;
		y = 80;  //the bottom of Top
		AppearTime = 300;//10s
		time = AppearTime; 
		image = GameUtil.loadBufferedImage(Constant.ENEMYFLY_IMG_PATH);
		
	}
	
	public void draw(Graphics g) {
		if(time >= 0) {
			g.drawImage(image, x, y, null);
		}
	}
	
	public void setEnemyFly(int x1) {
		x = x1;
		time = AppearTime;
	}
	
	public void subT() {
		if(time >= 0) {
			time -= 1;
		}
	}
	
	
	public int beAttack(ArrayList<Bullet> bullet) {
		for(int i = 0; i < bullet.size(); i++) {
			Bullet b = bullet.get(i);
			if(b.getDir() == -1 && x <= b.getX() && b.getX() <= x + 70) //EFly width=70
			{
				int d0 = Math.abs(b.getX() - x - 35);
				if(b.getY() <= (y + 89 - d0)) {
					bullet.remove(i);
					time = -1;
					return 1;
				}
			}
		}
		return 0;
	}
	
	public int getX() {
		return x;
	}
	
	public int getTime() {
		return time;
	}
}
